/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: 性能评估器相关源文件
 * Author: qingjicheng
 * Create: 2022-8-1
 */

#include "comm_time_evaluator.h"
#include "evaluator_log_def.h"
#include "hccl_evaluator_api.h"

HcclResult HcclEvaluateTimeCostRoughly(HcclOpInfo* op, HcclTopology* topo, float* cost)
{
    static HcclEvaluator::CommTimeEvaluator evaluator;
    return evaluator.EvaluateTimeCostRoughly(op, topo, cost);
}

namespace HcclEvaluator {
CommTimeEvaluator::CommTimeEvaluator()
{
}

CommTimeEvaluator::~CommTimeEvaluator()
{
}

HcclResult CommTimeEvaluator::EvaluateTimeCostRoughly(HcclOpInfo* op, HcclTopology* topo, float* cost)
{
    TimePoint start = TimeNow();
    EVALUATOR_CHK_PTR_NULL(op);
    EVALUATOR_CHK_PTR_NULL(topo);
    EVALUATOR_CHK_PTR_NULL(cost);
    ConnectedGraph graph;

    EVALUATOR_CHK_RET(graphBuilder_.BuildConnectedGraph(topo, graph));

    float costTime = 0;
    EVALUATOR_CHK_RET(graphAnalyzer_.AnalyzeGraphTimeCost(graph, *op, costTime));

    *cost = costTime;
    EVALUATOR_INFO("EvaluateTimeCostRoughly duration = %lld us\n", DurationUs(TimeNow() - start));
    return HCCL_SUCCESS;
}
} // namespace HcclEvaluator